package com.adam.example.newssearches5_4_0.mapper;

import com.adam.example.newssearches5_4_0.common.Pager;
import com.adam.example.newssearches5_4_0.po.NewsPO;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface NewsMapper {

    @Select({
            "SELECT id,title,key_word,content,url,reply,source,postdate FROM news",
            "LIMIT #{sqlStartOffset},#{pageSize}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT),
            @Result(column = "title", property = "title", jdbcType = JdbcType.VARCHAR),
            @Result(column = "key_word", property = "keyword", jdbcType = JdbcType.VARCHAR),
            @Result(column = "content", property = "content", jdbcType = JdbcType.VARCHAR),
            @Result(column = "url", property = "url", jdbcType = JdbcType.VARCHAR),
            @Result(column = "reply", property = "reply", jdbcType = JdbcType.VARCHAR),
            @Result(column = "source", property = "source", jdbcType = JdbcType.VARCHAR),
            @Result(column = "postdate", property = "postdate", jdbcType = JdbcType.TIMESTAMP)
    })
    List<NewsPO> queryByPage(Pager pager);

    @Select("SELECT COUNT(*) FROM news")
    long queryCount();

}
